Jump to content

Recommended Posts

Hello,

So I'm quite new to SQL, so please be patient :S

 

I have a page at http://myipodbroke.com/repair_info_test.php where users enter data.  This data is then stored in a SQL database.  When I try to access it though, I get errors (go to http://myipodbroke.com/ADMIN-database.php )

 

here's the code from the database accessing page that gives errors:

<?php
$username = "[username]";
$password = "[pass]";
$hostname = "localhost";
$database = "[database]";
mysql_connect($hostname, $username, $password)
or die("Unable to connect to database.");
mysql_select_db($database) 
or die("Could not select myipodbr_ipodusers");

$query="SELECT * FROM contacts";
$result=mysql_query($query);

$num=mysql_numrows($result);
echo "<b><center>Database Output</center></b><br><br>";

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

$id=mysql_result($result,$i,"id");
$fname=mysql_result($result,$i,"fname");
$lname=mysql_result($result,$i,"lname");
$address1=mysql_result($result,$i,"address1");
$address2=mysql_result($result,$i,"address2");
$city=mysql_result($result,$i,"city");
$state=mysql_result($result,$i,"state");
$zip=mysql_result($result,$i,"zip");
$sendemail=mysql_result($result,$i,"sendemail");
$phone=mysql_result($result,$i,"phone");
$refer=mysql_result($result,$i,"refer");
$refer2=mysql_result($result,$i,"refer2");
$generation=mysql_result($result,$i,"generation");
$promo=mysql_result($result,$i,"promo");
$problems=mysql_result($result,$i,"problems");

echo "<b>$id</b><br>
<b>$fname $lname</b><br>
$address1<br>
$address2<br>
$city $state $zip<br>
$sendemail<br>
$phone<br>
$refer $refer2<br>
$generation<br>
$promo<br>
$problems<br>
<hr><br>";

$i++;
}

mysql_close();
?>

 

oh and here's what the code is that writes info to the database:

$username = "myipodbr_peder";
$password = "u47tptr9";
$hostname = "localhost";
$database = "myipodbr_ipodusers";
mysql_connect($hostname, $username, $password)
or die("Unable to connect to database.");
mysql_select_db($database) 
or die("Could not select myipodbr_ipodusers");
$query="CREATE TABLE 
contacts 
(id int(6) NOT NULL auto_increment,
fname varchar(15) NOT NULL,
lname varchar(15) NOT NULL,
address1 varchar(20) NOT NULL,
address2 varchar(20) NOT NULL,
city varchar(20) NOT NULL,
state varchar(10) NOT NULL,
zip varchar(10) NOT NULL,
sendemail varchar(20) NOT NULL,
phone varchar(20) NOT NULL,
refer varchar(20) NOT NULL,
refer2 varchar(20) NOT NULL,
generation varchar(20) NOT NULL,
promo varchar(20) NOT NULL,
problems varchar(20) NOT NULL,
PRIMARY KEY (id),
UNIQUE id (id),
KEY id_2 (id))";
mysql_query($query);

$query = "INSERT INTO contacts VALUES ('','$fname','$lname','$address1','$address2','$city','$state','$zip','$sendemail','$phone','$refer','$refer2','$generation','$promo','$problems')";
mysql_query($query);

 

any help would be appreciated, thanks!

Link to comment
https://forums.phpfreaks.com/topic/167655-sql-help-accessing-database-table/
Share on other sites

first, it should be mysql_num_rows() not mysql_numrows()

 

but, you don't even need that:

<?php
$username = "[username]";
$password = "[pass]";
$hostname = "localhost";
$database = "[database]";
mysql_connect($hostname, $username, $password)
   or die("Unable to connect to database.");
mysql_select_db($database) 
   or die("Could not select myipodbr_ipodusers");

$query="SELECT * FROM contacts";
$result=mysql_query($query) or die(mysql_error());

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

while ($row = mysql_fetch_assoc($result)) {

echo "<b>{$row['id']}</b><br>
<b>{$row['fname']} {$row['lname']}</b><br>
{$row['address1']}<br>
{$row['address2']}<br>
{$row['city']} {$row['state']} {$row['zip']}<br>
{$row['sendemail']}<br>
{$row['phone']}<br>
{$row['refer']} {$row['refer2']}<br>
{$row['generation']}<br>
{$row['promo']}<br>
{$row['problems']}<br>
<hr><br>";
}

mysql_close();
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.