Jump to content

blank screen...HELP!!


veronika

Recommended Posts

Okay I KNOW that there is something wrong with this script.  I ran it to tested and got nothing on the display page.  Can someone  please take a look at it and point out errors? I'm still  trying to get this whole PHP stuff so please explain it as basic as possible.  :D

 

<?php

$sql="CREATE database hombudget";

$connection= @mysql_connect ("localhost","spike", "9sj7En4")

or die (mysql_error());

$result=@mysqlquery ($sql, $connection) or die (mysql_error());

mysql_select_db("homebudget", $connection)

$tbl= "CREATE TABLE 'estimate'

(

Category varchar (10),

Description varchar (30),

Budget int

)";

$slq = "

DROP DATABASE IF EXIST 'homebudget'

CREATE  TABLE 'expenses'

(

Category varchar (10),

espenseData DATE,

expenditure INT

)";

$result=mysql_query (4sql, $connection)

or die (mysql_error());

if ($results) {

$msg  =  "</P>Database Homebudgethas been created </P>";

}

?>

<HTML>

<HEAD>

<TITLE>Homebudget Database</TITLE>

</HEAD>

<BODY>

<?php echo  "$msg";

?>

</BODY>

</HTML>

 

This is what my im trying to accomplish:

Grant spike user all permissions on everything controlled by the DBMS.

• Create a database named "homebudget".

• Within that database, create two tables:

o The first table should be named "estimates". Give it three fields:

 VARCHAR of length 10 named "category"

 VARCHAR of length 30 named "description"

 INT named "budget"

o The second table should be named "expenses". Give it three fields:

 VARCHAR of length 10 named "category"

 DATE named "expenseDate"

 INT named "expenditure"

• Create a script file named solutionA.php. Within that script, connect to your DBMS using the "script" identity. Select the "homebudget" database, then obtain a listing of the tables.

 

 

Link to comment
Share on other sites

If you want to see all your errors, remove your error supressions (@ symbol) from the beginning of function calls.

 

I'll give you a hint though, there are quite a few.  Just to point out the ones I spotted:

 

<?php
$sql="CREATE database hombudget";
$connection= @mysql_connect ("localhost","spike", "9sj7En4")
or die (mysql_error());
$result=@mysqlquery ($sql, $connection) or die (mysql_error());
mysql_select_db("homebudget", $connection)
$tbl= "CREATE TABLE 'estimate'
(
Category varchar (10),
Description varchar (30),
Budget int
)"; // You might want a primary key
$slq = "
DROP DATABASE IF EXIST 'homebudget'
CREATE  TABLE 'expenses'
(
Category varchar (10),
espenseData DATE,
expenditure INT
)"; // Did you leave this in intentionally?
$result=mysql_query (4sql, $connection) // 4 rather than $ sign
or die (mysql_error());
if ($results) { // Variable doesn't exist
$msg  =  "</P>Database Homebudgethas been created </P>"; // Where's the beginning P tag?
}
?>
<HTML>
<HEAD>
<TITLE>Homebudget Database</TITLE>
</HEAD>
<BODY>
<?php echo  "$msg"; // No need for quotation marks here
?>
</BODY>
</HTML>

 

Quite frankly without trying to sound rude, it's quite a mess in there.

 

 

 

Link to comment
Share on other sites

Not offended here!!! I know this is wrong and Im just trying to get some guidance and trying to understand what work and why?THANKS for the help!!!

 

<?php

$sql="CREATE database hombudget";

$connection= mysql_connect ("localhost","spike", "9sj7En4")

or die (mysql_error());

$result=mysqlquery ($sql, $connection) or die (mysql_error());

mysql_select_db("homebudget", $connection)

$tbl= "CREATE TABLE estimate

(

Category varchar (10),

Description varchar (30),

Budget int

)";// i don't know what you mean by a primary key? what it that?

$slq = "

DROP DATABASE IF EXIST 'homebudget'

CREATE  TABLE 'expenses'

(

Category varchar (10),

espenseData DATE,

expenditure INT

)";//do I  need to remover the ; what is the purpose of that? just wondering because my

book examples have them

$result=mysql_query ($sql, $connection)//isn't this the $result variable?

or die (mysql_error());

if ($results) {

$msg  =  "<P>Database Homebudget  has been created </P>";

}

?>

<HTML>

<HEAD>

<TITLE>Homebudget Database</TITLE>

</HEAD>

<BODY>

<?php echo $msg;

?>

</BODY>

</HTML>

Link to comment
Share on other sites

Primary Key

A primary key is an auto-incrementing number which is unique to each row of the database table.  It allows you to uniquely identify each row, as other values may change.

 

)";//do I  need to remover the ; what is the purpose of that? just wondering because my book examples have them

I didn't mean that line of code, I meant the entire variable.  It's called $slq rather than $sql, and I wondered whether you changed the name of it so that it wasn't used.

 

$result=mysql_query ($sql, $connection)//isn't this the $result variable?

It is, but your if() statement is looking for $results.

Link to comment
Share on other sites

I'll be rude. Do you even read your code? There are so many errors in that I don't know where to begin. There are simple syntax errors and there are significant logic problems.

 

Take this example:

mysql_select_db("homebudget", $connection)
//...
$slq = "
DROP DATABASE IF EXIST 'homebudget'
CREATE  TABLE 'expenses'
(
Category varchar (10),
espenseData DATE,
expenditure INT
)";
$result=mysql_query (4sql, $connection)

 

You first connect to the database "homebudget", then a little bit later you delete it and try to run another query. To which database would you be running that query since you just deleted the one you connected to?

 

I understand that you are still trying to learn, but I count at least 4 typos/syntax errors that have nothing to do with being new to PHP:

 

$result=@mysqlquery ($sql, $connection) or die (mysql_error());

It is mysql_query()

 

mysql_select_db("homebudget", $connection)

Missing a semi-colon at the end of the line

 

$slq = "

You meant to use $sql

 

$result=mysql_query (4sql, $connection)
or die (mysql_error());

Should be $sql

 

Take your time and check your work. Learn how to debug. Write some code and test it. When you have IF/ELSE conditions, create the necessary parameters to get the results of each condition.

Link to comment
Share on other sites

If you are copying this code from a book or a tutorial and the original contains these errors, you have got to ask yourself if this book or tutorial is worth your time.

 

If the errors... typos are a result of your 'translation' between the book and your editor, I've got to tell you that computers only do exactly what their code tells them to do. There is no leeway in coding. Everything must be exact. Everything (including underscores, punctuation...) is there for a reason or it would not be in the code.

 

Also when learning php, developing php code, or debugging php code, please do it on a system with error_reporting set to E_ALL and display_errors set to ON in your master php.ini so that php will help you by displaying all the errors it detects. You will save a TON of time. Stop and start your server to get any change made to the master php.ini to take effect and confirm the settings afterwards in case the php.ini that you are changing is not the one that php is using.

Link to comment
Share on other sites

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.