Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Gettin started with PHP/MySQL
Old 04-20-2005, 07:12 PM Gettin started with PHP/MySQL
Justin-Credible's Avatar
Novice Talker

Posts: 12
Trades: 0
I'm new to working with MySQL through PHP. I was following this tutorial http://www.freewebmasterhelp.com/tutorials/phpmysql/4

I was able to create a database and enter information into with though PHP scripting, but I'm stuck on outputting it (see link).

This is the error I get when I browse to my out.php page:

Quote:
Warning: mysql_query(): Unable to save result set in D:\websites\wwwroot\temp\out.php on line 9

Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in D:\websites\wwwroot\temp\out.php on line 11

Database Output
If I log into MySQL from a command line and type "SELECT * FROM contacts;" it spits out the entries in the database:

Quote:
mysql> SELECT * FROM contacts;
+----+-------+-------+--------------+--------------+--------------+-------------
------------+--------------------------+
| id | first | last | phone | mobile | fax | email
| web |
+----+-------+-------+--------------+--------------+--------------+-------------
------------+--------------------------+
| 1 | John | Smith | 01234 567890 | 00112 334455 | 01234 567891 | johnsmith@go
wansnet.com | http://www.gowansnet.com |
+----+-------+-------+--------------+--------------+--------------+-------------
------------+--------------------------+
1 row in set (0.00 sec)
Any ideas?
Justin-Credible is offline
Reply With Quote
View Public Profile Visit Justin-Credible's homepage!
 
 
Register now for full access!
Old 04-20-2005, 07:29 PM
leavethisplace's Avatar
Ultra Talker

Posts: 297
Trades: 0
that looks more like a PHP error to me, which means your coding may have something wrong with it. We can help you a little better if you post your code, im not promising anything though!
__________________
A lie gets halfway around the world before the truth has a chance to get its pants on. - Sir Winston Churchill

Please visit my sites:
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
leavethisplace is offline
Reply With Quote
View Public Profile
 
Old 04-20-2005, 07:38 PM
Justin-Credible's Avatar
Novice Talker

Posts: 12
Trades: 0
I copy and pasted everying from out.php from the tutorial page and just changed the info for the database/username/password:

OUT.PHP
PHP Code:
<?
$username
="Justin";
$password="xxxxxx";
$database="justin";

mysql_connect("localhost",$username,$password);
@
mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM contacts";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

echo 
"<b><center>Database Output</center></b><br><br>";

$i=0;
while (
$i $num) {

$first=mysql_result($result,$i,"first");
$last=mysql_result($result,$i,"last");
$phone=mysql_result($result,$i,"phone");
$mobile=mysql_result($result,$i,"mobile");
$fax=mysql_result($result,$i,"fax");
$email=mysql_result($result,$i,"email");
$web=mysql_result($result,$i,"web");

echo 
"<b>$first $last</b><br>Phone: $phone<br>Mobile: $mobile<br>Fax: $fax<br>E-mail: $email<br>Web: $web<br><hr><br>";

$i++;
}

?>

I also noticed the page for inputing values to the database through a form on an HTML page doesn't work. When I click submit I get the standard "this page cannot be displayed" message.

Page.html:
HTML Code:
<html>
<body>
<form action="insert.php" method="post">
First Name: <input type="text" name="first"><br>
Last Name: <input type="text" name="last"><br>
Phone: <input type="text" name="phone"><br>
Mobile: <input type="text" name="mobile"><br>
Fax: <input type="text" name="fax"><br>
E-mail: <input type="text" name="email"><br>
Web: <input type="text" name="web"><br>
<input type="Submit">
</form>
</body>
</html>
Insert.php:
PHP Code:
<?
$username
="Justin";
$password="xxxxx";
$database="justin";

$first=$_POST['first'];
$last=$_POST['last'];
$phone=$_POST['phone'];
$mobile=$_POST['mobile'];
$fax=$_POST['fax'];
$email=$_POST['email'];
$web=$_POST['web'];

mysql_connect("localhost",$username,$password);
@
mysql_select_db($database) or die( "Unable to select database");

$query "INSERT INTO contacts VALUES ('','$first','$last','$phone','$mobile','$fax','$email','$web')";
mysql_query($query);

mysql_close();
?>
Justin-Credible is offline
Reply With Quote
View Public Profile Visit Justin-Credible's homepage!
 
Old 04-20-2005, 07:47 PM
leavethisplace's Avatar
Ultra Talker

Posts: 297
Trades: 0
Hmm, im not sure if that PHP code is completely incorrect for the query, but it certainly seems an odd way to go about it, try using this instead:

PHP Code:
$query "SELECT * FROM contacts"
$result mysql_query($query); 

echo 
"<b><center>Database Output</center></b><br><br>"

/* Line below will go through every row of the result, and put them in the array, using the 
cell names as a key, so that they can be called using $row['cellname']; */

while ( $row mysql_fetch_array($result) ) {

$first $row['first'];
$last$row['second'];
$phone $row['phone'];
$mobile $row['mobile'];
$fax $row['fax'];
$email $row['email'];
$web $row['web'];
echo 
"<b>$first $last</b><br>Phone: $phone<br>Mobile: $mobile<br>Fax: $fax<br>E-mail: $email<br>Web: $web<br><hr><br>"



// Close mySQL when you've finished with it
mysql_close(); 
That should sort it out, but do post back if you have problems. If this does fix it, then slam that tutorial and check out this one that i recommend every single time!
__________________
A lie gets halfway around the world before the truth has a chance to get its pants on. - Sir Winston Churchill

Please visit my sites:
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
leavethisplace is offline
Reply With Quote
View Public Profile
 
Old 04-21-2005, 04:51 PM
Justin-Credible's Avatar
Novice Talker

Posts: 12
Trades: 0
I tried using the code you gave me and got this error:

Code:
Warning: mysql_query(): Unable to save result set in D:\websites\wwwroot\temp\out2.php on line 12

Database Output



Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\websites\wwwroot\temp\out2.php on line 19
I'm assuming this means my coding is OK, but it seems like PHP or MySQL is having issues here. I'm not sure what to do though because we have other PHP/MySQL applications working perfectly on this same server.
Justin-Credible is offline
Reply With Quote
View Public Profile Visit Justin-Credible's homepage!
 
Old 04-21-2005, 05:08 PM
Justin-Credible's Avatar
Novice Talker

Posts: 12
Trades: 0
I tried the tutorial on a different server and it worked no problem. I guess ISS is locked down too tightly on the first server.

Has anyone had this problem before?
Justin-Credible is offline
Reply With Quote
View Public Profile Visit Justin-Credible's homepage!
 
Old 04-21-2005, 10:30 PM
Gaffer Sports's Avatar
Ultra Talker

Posts: 397
Name: Steve
Location: Scotland
Trades: 1
IIS can be a right pain in the behind, simply because the owner did not think of PHP.

I have had experiences of Dedicated servers and they are great for certain things and a nightmare for others. If you go for a host that offers a Windows package, make sure they know how to configure it or you can have plenty of downtime.

Likewise, if you decide to dedicate your time to a server, make sure you read up on it first as it is not as simple as linux.

Steve.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
Gaffer Sports is offline
Reply With Quote
View Public Profile Visit Gaffer Sports's homepage!
 
Old 04-22-2005, 04:29 PM
Justin-Credible's Avatar
Novice Talker

Posts: 12
Trades: 0
Both of the servers are my own, I host my own stuff.

I ran the ISS lockdown wizard to unlock all the restrictions that I had put in place (which unfortunately deleted all of my virtual directories ). Anyways after I got everything back up and running I got the PHP fixed. There are still some weird things happening, but I'm getting closer.
Justin-Credible is offline
Reply With Quote
View Public Profile Visit Justin-Credible's homepage!
 
Old 04-22-2005, 04:39 PM
merlin's Avatar
Skilled Talker

Posts: 52
Trades: 0
I might be right out to lunch but I've had this error before and found if I put a "@" in front of the mysql_fetch_array it corrected the problem. On the other hand I could be completely missing the point and not helping at all.

You could try this:

PHP Code:
while ( $row = @mysql_fetch_array($result) ) { 
merlin is offline
Reply With Quote
View Public Profile
 
Old 04-22-2005, 10:34 PM
leavethisplace's Avatar
Ultra Talker

Posts: 297
Trades: 0
mysql_fetch_array() is an array anyway isn't it? So putting the @ there isn't going to be much difference?

Oberon needed here!
__________________
A lie gets halfway around the world before the truth has a chance to get its pants on. - Sir Winston Churchill

Please visit my sites:
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
leavethisplace is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Gettin started with PHP/MySQL
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.31703 seconds with 12 queries